package com.log.rest;

import com.log.biz.LogBiz;
import com.log.entity.Logs;
import com.log.response.ObjectRestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author zwj
 * @date 2021-04-08
 */
@RestController
@RequestMapping("/api/logs")
@Api(tags = "监控：日志管理")
@SuppressWarnings("unchecked")
public class LogController {


    @Autowired
    private LogBiz logBiz;

    //    @Logs("导出数据")
//    @ApiOperation("导出数据")
//    @GetMapping(value = "/download")
//    public void download(HttpServletResponse response, LogQueryCriteria criteria) throws IOException {
//        criteria.setLogType("INFO");
//        logBiz.download(logService.queryAll(criteria), response);
//    }
//
//    @Logs("导出错误数据")
//    @ApiOperation("导出错误数据")
//    @GetMapping(value = "/error/download")
//    public void errorDownload(HttpServletResponse response, LogQueryCriteria criteria) throws IOException {
//        criteria.setLogType("ERROR");
//        logBiz.download(logService.queryAll(criteria), response);
//    }

    @GetMapping
    @ApiOperation("日志查询")
    public ObjectRestResponse<Object> getLogs() {
        List<Logs> logs = logBiz.selectListAll();
        return new ObjectRestResponse<>().success(logs);
    }
//
//    @GetMapping(value = "/mlogs")
//    public ResponseEntity getApiLogs(LogQueryCriteria criteria, Pageable pageable) {
//        criteria.setLogType("INFO");
//        criteria.setType(1);
//        return new ResponseEntity(logService.findAllByPageable(criteria.getBlurry(), pageable), HttpStatus.OK);
//    }
//
//    @GetMapping(value = "/user")
//    @ApiOperation("用户日志查询")
//    public ResponseEntity<Object> getUserLogs(LogQueryCriteria criteria, Pageable pageable) {
//        criteria.setLogType("INFO");
//        criteria.setBlurry(BaseContextHandler.getUsername());
//        return new ResponseEntity<>(logService.queryAllByUser(criteria, pageable), HttpStatus.OK);
//    }
//
//    @GetMapping(value = "/error")
//    @ApiOperation("错误日志查询")
//    public ResponseEntity<Object> getErrorLogs(LogQueryCriteria criteria, Pageable pageable) {
//        criteria.setLogType("ERROR");
//        return new ResponseEntity<>(logService.queryAll(criteria, pageable), HttpStatus.OK);
//    }
//
//    @GetMapping(value = "/error/{id}")
//    @ApiOperation("日志异常详情查询")
//    public ResponseEntity<Object> getErrorLogs(@PathVariable Long id) {
//        return new ResponseEntity<>(logService.findByErrDetail(id), HttpStatus.OK);
//    }
//
//    @DeleteMapping(value = "/del/error")
//    @Logs("删除所有ERROR日志")
//    @ApiOperation("删除所有ERROR日志")
//    public ResponseEntity<Object> delAllByError() {
//        logService.delAllByError();
//        return new ResponseEntity<>(HttpStatus.OK);
//    }
//
//    @DeleteMapping(value = "/del/info")
//    @Logs("删除所有INFO日志")
//    @ApiOperation("删除所有INFO日志")
//    public ResponseEntity<Object> delAllByInfo() {
//        logBiz.delAllByInfo();
//        return new ResponseEntity<>(HttpStatus.OK);
//    }
}
